/**
 * @file   testSharedPtr.cpp
 * @author wolfhead <wolfhead@wolfhead-laptop>
 * @date   Tue Sep 20 20:01:39 2011
 * 
 * @brief  
 * 
 * 
 */
#include <stdio.h>
#include <acapella/shared_ptr.hpp>

using namespace acapella;

class Test;
//typedef Test* TestPtr;
typedef shared_ptr<Test> TestPtr;





//#define printf(...) (void(0))

static size_t count = 0;

class Test
{
public:
	Test()
	{
        ++count;
		//printf("create test %p\n", this);
	}

	~Test()
	{
        --count;
		//printf("destroy test %p\n", this);
	}

	TestPtr test1(TestPtr p)
	{
		//printf("test1 : %p\n", p.get());

		p = TestPtr(new Test);
		return p->test2(p);
	}

	TestPtr test2(TestPtr p)
	{
		//printf("test2 : %p\n", p.get());
		return TestPtr(new Test);
	}
};


int main()
{
    int i = 1000000;
    while (i--)
    {
        TestPtr a(new Test);
        TestPtr b(new Test);

        a = a->test1(a);
        b = a->test2(a);
    }

    printf("%d", count);

	return 0;
}

